﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace John
{
    public partial class Default2 : System.Web.UI.Page
    {


        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["CID"] = null;

                if (Request.QueryString["cid"] != null)
                {
                    string strCID = Request.QueryString["cid"].ToString();
                    ViewState["CID"] = CleanString.htmlInputText(strCID);
                }
                PData();
                HData();
                newData();             
               
            }
        }
        private void PData()//产品列表绑定
        {
            if (ViewState["CID"] == null)
            {
                //分页
                mySqlPager.setAttribute(SqlPager1, "PDataList", "select * from zhaoshang order by ID desc", "1000000-ID", 20);

                lblDaohang.Text = "创业加盟";
            }
            else
            {
                string strCID = ViewState["CID"].ToString();
                DBConn myDB = new DBConn();
                string sql = "select * from zhaoshang where zspfl=" + strCID + " order by ID desc";
                try
                {
                    //分页
                    mySqlPager.setAttribute(SqlPager1, "PDataList", sql, "1000000-ID", 20);
                }
                catch
                {
                    Response.Write("<script>");
                    Response.Write("alert('没有记录!!!');");
                    Response.Write("</script>");
                    myDB.Close();
                    Response.Redirect("Default.aspx");
                    return;
                }
                myDB.Close();

                DBConn DB = new DBConn();
                string mySql = "select * from Category where CID=" + strCID;
                SqlDataReader dr = DB.getDataReader(mySql);
                if (dr.Read())
                {
                    lblDaohang.Text = dr["CName"].ToString();
                }
                else
                {
                    Response.Write("<script>");
                    Response.Write("alert('没有这个类别!!!');");
                    Response.Write("</script>");
                    dr.Close();
                    DB.Close();
                    Response.Redirect("Default.aspx");
                    return;
                }
                dr.Close();
                DB.Close();
            }
        }       
        private void HData()//推荐列表绑定
        {
           DBConn myDB = new DBConn();
           string sql = "select top 10 * from zhaoshang where zsftg=1 ";
           HotRepeater.DataSource = myDB.getDataReader(sql);
           HotRepeater.DataBind();
           myDB.Close();

        }
        private void newData()//最新列表绑定
        {
            DBConn myDB = new DBConn();
            string sql = "select top 10 * from zhaoshang order by id desc";
            Repeater1.DataSource = myDB.getDataReader(sql);
            Repeater1.DataBind();
            myDB.Close();
            

        }
      
    }
}
